home *** CD-ROM | disk | FTP | other *** search
- {*
- * FormulaBuilder 1.0
- * YGB Software, Inc.
- * Delphi Wrapper Class
- * Copyright (c) 1995 Clayton Collie
- * All Rights Reserved
- *}
- {$F+,V-,X+,W-,G+,N+,A+}
- UNIT FBCOMP;
- INTERFACE
- uses classes,sysutils,fbcalc;
- CONST
- MAXEXPRESSIONLEN = 1024;
- MAXVARNAMELEN = 30;
-
- EXPR_UNHANDLED_EVENT = 200;
-
-
- Type
- TVarname = String[MAXVARNAMELEN+1];
-
-
- TVariable = Record
- Name : TVarName;
- Value : TValueRec;
- end;
-
-
-
- EFBError = Class(Exception)
- Protected
- fErrCode : Integer;
- Public
- Constructor CreateEcode(const ecode : integer);
- Property ErrorCode : integer read fErrCode write fErrCode;
- end;
-
-
-
- TFindVariableEvent = Procedure(const varname : string;
- var vtype : byte;
- var errcode : integer;
- var vardata : longint) of object;
-
- TGetVariableEvent = Procedure(const varname : string;
- var value : TValueRec;
- var errcode : integer;
- vardata : longint) of object;
-
- TSetVariableEvent = Procedure(const varname : string;
- const value : TValueRec;
- var errcode : integer;
- vardata : longint) of object;
-
-
-
- TCustomExpression = class(TComponent)
- private
- {* unlisted *}
- protected
- fLines : TStrings;
- Procedure SetExpression(const expr : pchar); virtual;
- Procedure SetVariableCallbacks(CBKVFind : TCBKFindVariable;
- CBKVGetval : TCBKGetVariable;
- CBKVSetVal : TCBKSetVariable;
- lCBKData : longint);
- Procedure FreeConstants;
-
- Property UseEvents : boolean
- read fUseEvents write setUseEvents;
-
- Property OnFindVariable : TFindVariableEvent
- read fOnFindVariable
- write SetFindVarEvent;
-
- Property OnGetVariable : TGetVariableEvent
- read fOnGetVariable
- write SetGetVarEvent;
-
- Property OnSetVariable : TSetVariableEvent
- read fOnSetVariable
- write SetSetVarEvent;
-
-
- Property BooleanResult : boolean read EvalAsBoolean;
- Property DateResult : TDateTime read EvalAsDate;
- Property FloatResult : Double read EvalAsFloat;
- Property FunctionCount : word read getFunctionCount;
- Property StringResult : String read EvalAsString;
- Property IntResult : Longint read EvalAsInt;
-
- Public
- Constructor Create(aOwner : TComponent); override;
- Destructor Destroy; override;
- Procedure Clear; virtual;
- Procedure Reparse; virtual;
-
- Procedure EvaluatePrim(var value : TVALUEREC); virtual;
- Procedure AddVariable(const vname : TVarName;vtype : byte);
- Procedure getVarPtr(const vname : TVarName;var vtype : byte;var value : pointer);
- Procedure FreeVariable(const vname : TVarName);
- Procedure FreeVariableList;
-
- Procedure AddConstantPrim(const cname : TVarName;value : TValueRec);
- Procedure AddStringConstant(const cname : TVarName;value : string);
- Procedure AddDateConstant(const cname : TVarName;value : TFBDate);
- Procedure AddNumericConstant(const cname : TVarName;value : double);
- Procedure AddBooleanConstant(const cname : TVarName;value : boolean);
- Procedure ParseAddVariable(const vname : TVarName;expr : string);
- Procedure ParseAddConstant(const cname : TVarName;expr : string);
- Procedure FreeConstant(const cname : TVarName);
- { }
- Function StatusText : string; virtual;
-
- Property Formula : String read getInfix
- write setInfix;
-
- Property AsString : string read ValueAsString;
- { write setInfix; }
-
- Property Lines : TStrings read FLines
- write SetLines;
-
- Property ReturnType : byte read fReturnType;
-
-
- Property Status : integer read fStatus
- write setStatus;
-
- Property StrFormula : PChar read getExpression
- write setExpression;
-
- Property UseExceptions : boolean read fUseExceptions
- write fUseExceptions
- default true;
-
- Property VariableCount : integer read getVariableCount;
-
- Property VariableList[i : integer]:TVariable
- read getNthVarPrim
- write setNthVarPrim;
-
- Property Variables[const vname : TVarName] : TValueRec
- read getVariablePrim
- write setVariablePrim;
-
- Property StringValues[const vname : TVarName] : String
- read getVarAsString
- write setVarFromString;
-
- Property Constants[const cname : TVarName] : TValueRec
- read getConstantPrim
- write AddConstantPrim;
-
- Property Handle : HEXPR read fHandle;
- Property IsNULL : boolean read fIsEmpty;
-
- { Events }
-
- end;
-
-
- TExpression = Class(TCustomExpression)
- Public
- Property AsBoolean;
- Property AsDate;
- Property AsFloat;
- Property AsInteger;
- Property AsString;
- Property FunctionCount;
- Property ReturnType;
- Published
- Property Formula;
- Property Lines;
- Property UseExceptions;
- { events }
- Property OnFindVariable;
- Property OnGetVariable;
- Property OnSetVariable;
- Property UseEvents;
- end;
-
-
- Procedure Register;
-
- function ValueAsString(const Fvalue : TValueRec): string;
-
- Function getFunctionPrototypes(useResultType : boolean) : TStringList;
-
-
- IMPLEMENTATION
- END.
-